#ifndef _VECTOR2_HPP_
#define _VECTOR2_HPP_

#include <math.h>

class Vector2 {
public:

	float x;
	
	float y;
	
public:

	float* getPtr() {
		return (float*)this;
	}

	const float* getPtr() const {
		return (float*)this;
	}
	
	float& operator[] (unsigned int index) {
		return ((float*)this)[index];
	}
	
	Vector2 operator + (const Vector2& v) const {
		return Vector2(x + v.x, y + v.y);
	}
	
	Vector2 operator - (const Vector2& v) const {
		return Vector2(x - v.x, y - v.y);
	}

	Vector2 operator * (const Vector2& v) const {
		return Vector2(x * v.x, y * v.y);
	}

	Vector2 operator / (const Vector2& v) const {
		return Vector2(x / v.x, y / v.y);
	}
	
	void operator += (const Vector2& v) {
		x += v.x;
		y += v.y;
	}
	
	void operator -= (const Vector2& v) {
		x -= v.x;
		y -= v.y;
	}

	void operator *= (const Vector2& v) {
		x *= v.x;
		y *= v.y;
	}

	void operator /= (const Vector2& v) {
		x /= v.x;
		y /= v.y;
	}

	Vector2 operator + (float s) const {
		return Vector2(x + s, y + s);
	}
	
	Vector2 operator - (float s) const {
		return Vector2(x - s, y - s);
	}

	Vector2 operator * (float s) const {
		return Vector2(x * s, y * s);
	}

	Vector2 operator / (float s) const {
		return Vector2(x / s, y / s);
	}
	
	void operator += (float s) {
		x += s;
		y += s;
	}
	
	void operator -= (float s) {
		x -= s;
		y -= s;
	}

	void operator *= (float s) {
		x *= s;
		y *= s;
	}

	void operator /= (float s) {
		x /= s;
		y /= s;
	}
	
public:

	/*
		Длинна вектора
	*/

	float length() const {
		return sqrt(x * x + y * y);
	}
	
	/*
		Длинна вектора
	*/

	static float length(const Vector2& v) {
		return v.length();
	}
	
	/*
		Расстояние между двумя векторами
	*/
	
	static float distance(const Vector2& v1, const Vector2& v2) {
		return (v2 - v1).length();
	}
	
	/*
		Скалярное произведение (dot product)
	*/
	
	static float dot(const Vector2& v1, const Vector2& v2) {
		return (v1.x * v2.x + v1.y * v2.y);
	}
	
	/*
		Нормализация
	*/
	
	static Vector2 normalize(const Vector2& v) {
		return v * (1.0f / v.length());
	}

	/*
		Линейная интерполяция
	*/
	
	static Vector2 lerp(const Vector2& v1, const Vector2& v2, float a) {
		return Vector2(
			(v2.x - v1.x) * a + v1.x,
			(v2.y - v1.y) * a + v1.y
		);
	}
	
public:

	Vector2(float s) {
		Vector2::x = s;
		Vector2::y = s;
	}

	Vector2(float x, float y) {
		Vector2::x = x;
		Vector2::y = y;
	}
	
	Vector2() {
	}
	
};

#endif